home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / Documentation / Engineering Notes / Data Interchange / Content Model next >
Encoding:
Text File  |  1996-04-26  |  9.1 KB  |  201 lines  |  [TEXT/ttxt]

  1. OpenDoc
  2. Development
  3. Framework
  4.                                                                                                                                                                                                  
  5. Content Model 
  6. ODF Release 1                                                                                                                                                                          
  7.  
  8.  
  9. Table of Contents
  10. -------------------
  11. • What is the Content Model?
  12. • Implementing the Content Model
  13. • Who calls What?  And When?
  14.  
  15.  
  16. What is the Content Model?
  17.  
  18. The Content Model is a way of factoring part data so that the part-specific code for internalizing and externalizing data is gathered in one class hierarchy. Every part with persistent data should define a subclass of FW_CContent (or FW_CEmbeddingContent).  This content object holds the part’s persistent data, and provides Internalize and Externalize methods for reading and writing that data to a storage unit. 
  19.  
  20. In previous releases of ODF (and in parts written directly in OpenDoc), the part object contained all the data. Methods for in/externalizing the data were defined for both the part class and the selection class, so that often the same or similar code was duplicated across several classes (e.g. FW_CPart::ExternalizeContent, FW_CSelection::DoExternalizeSelection, FW_CSelection:: ExternalizeData).  In ODF 1 the user can define a hierarchy of content classes so that code that deals with one kind of data can be shared as needed.
  21.  
  22. In addition to managing part data, a content object is used to designate a subset of part data in a selection, promise, or link.  If the part supports data interchange operations like clipboard commands or drag and drop, it must define a selection class, which should have an associated content object for designating the selected data. Depending on what kind of data the part manages, the selection’s content class may hold the data itself (e.g. ODFHello, ODFEmbed) or point to a subset of the part’s data (e.g. ODFDraw, ODFContainer).
  23.  
  24. Whenever a data interchange operation is initiated (cut, copy, paste, drag, drop), the selection’s content object is called upon to read or write its data. The selection object’s content class must override a small number of methods that perform in/externalization of the selected data.
  25.  
  26. Examples:
  27.      - Hello part’s “selection” is the text displayed by the part. The selection object doesn’t have its own content object, but simply refers to that of the part.
  28.  
  29.      - Table part’s data consists of a list of embedded parts (proxies), each of which is located in a cell of the table. A selection consists of a single cell, which may or may not contain a proxy. The selected cell is indicated by the cell’s coordinates.
  30.  
  31.      - Draw part’s data consists of a list of shapes. The selection’s content object keeps its own list of shape pointers. 
  32.  
  33. See also the section “Defining your Part’s Content Object” on p.45 of the ODF Developer’s Guide.
  34.  
  35.  
  36. Implementing the content model
  37.  
  38. The amount of work that needs to be done to implement the content model in a part depends on whether the part supports embedding or data interchange. In addition to the basic content methods Externalize and Internalize, embedding parts must override two or three methods to handle the single-embedded-frame case. Parts that support data interchange must define a selection object and its associated content object. Additional content classes may be needed to support promises and linking. 
  39.  
  40. The following is an outline of the basic steps for adding a content model to an ODF part. Part types are divided into four cases, going from simple to complex.
  41.  
  42. Case 1) Non-embedding part, no data interchange
  43. Example: Clock
  44.  
  45.       Subclass FW_CContent (holds part data)
  46.       Override FW_CContent::Externalize and FW_CContent::Internalize
  47.       Override FW_CPart::NewPartContent (creates and returns a content object)
  48.       The part should keep a pointer to its content object, in order to access its data.
  49.  
  50. Case 2) Non-embedding part with data interchange
  51. a) Selected data is all of the part data
  52. Example: Hello
  53.  
  54. In addition to steps in (1):
  55.       Subclass FW_CSelection
  56.       Override FW_CSelection::GetSelectedContent (returns part’s Content object)
  57.       Override standard selection methods: ClearSelection, CloseSelection, IsEmpty, SelectAll
  58.       Subclass undo-able command classes (FW_CClipboardCommand, FW_CDragCommand, FW_CDropCommand)
  59.       Implement undoable commands
  60.  
  61. b) Selected data is a subset of the part data
  62. Example: Bitmap
  63.  
  64. In addition to steps in (1) and (2a):
  65.       Subclass FW_CContent (designates selected data)
  66.       Override FW_CContent method Externalize (writes the selected data)
  67.       Override FW_CContent method Internalize (reads data into the selection)
  68.       In your override of FW_CSelection::GetSelectedContent, return the Content object for the selection, not the part
  69.  
  70.  
  71.  
  72. Case 3) Embedding part, no data interchange
  73. Examples: none
  74.       Subclass FW_CEmbeddingContent (holds part data)
  75.       Override FW_CContent methods Externalize and Internalize (writes and reads part data, respectively)
  76.       Override FW_CEmbeddingContent method IsDataOnlyOneProxy (tells if selected data is a single proxy)
  77.       Override FW_CEmbeddingContent method SingleEmbeddedFrameInternalized (adds newly embedded part to part data)
  78.       Override FW_CPart::NewPartContent (creates and returns a Content object)
  79.       Part should keep a pointer to its content object, in order to access the data.
  80.  
  81.  
  82. Case 4) Embedding part with data interchange
  83. a) Selected data is all of the part data
  84. Example: Embed
  85.  
  86. In addition to steps in (3):
  87.       Subclass FW_CSelection
  88.       Override FW_CSelection::GetSelectedContent (returns part’s Content object)
  89.       Override standard selection methods: ClearSelection, CloseSelection, IsEmpty, SelectAll
  90.       Subclass undo-able command classes (FW_CClipboardCommand, FW_CDragCommand, FW_CDropCommand, FW_CInsertCommand)
  91.       Implement undoable commands
  92.  
  93. b) Selected data is a subset of the part data
  94. Examples: Draw, Table, Container
  95. In addition to steps in (3) and (4a):
  96.       Subclass FW_CEmbeddingContent (holds selected data)
  97.       Override FW_CContent method Externalize (writes selected data)
  98.       Override FW_CContent method Internalize (reads data into the selection)
  99.       Override FW_CEmbeddingContent method IsDataOnlyOneProxy (tells if selected data is a single proxy)
  100.       Override FW_CEmbeddingContent method SingleEmbeddedFrameInternalized (adds newly embedded part to selection’s content)
  101.       In your override of FW_CSelection::GetSelectedContent, return the Content object for the selection, not the part
  102.  
  103.  
  104. Who Calls What? And When?
  105.  
  106. Below are some diagrams intended to illustrate how user-supplied methods fit into the ODF content model flow of control. This interaction diagram notation is adapted from that presented in the book Design Patterns, by Gamma, Helm, Johnson, and Vlissides.   The time line flows from top to bottom. A rectangle represents an object that is executing a request, and a vertical line indicates the lifetime of an object. Horizontal arrows denote requests sent to other objects. Functions that are provided by ODF are white rectangles, functions that must be supplied by the part writer are filled, and functions that may be overridden are striped.
  107.  
  108. Diagram 1 shows the flow of execution when OpenDoc tells a part to Externalize its data. The part itself only needs to override the Externalize method of its Content class. If necessary the part may also override its AddProperties method.
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. Diagram 1
  123.  
  124.  
  125. Diagram 2 shows the flow of execution when OpenDoc tells a part to internalize its data from a storage unit at part initialization time. Only the Internalize method of the part’s Content class must be overridden. The part may also override the Initialize method to perform part-specific initialization.
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137. Diagram 2
  138.  
  139.  
  140.  
  141. Diagram 3 shows what happens when selected data is externalized, as in a Copy or Drag command. To externalize a selection, you need to override at least the Externalize method of your selection’s Content class:
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156. Diagram 3
  157.  
  158.  
  159. Diagram 4 shows what happens when data is internalized into a selection object, as in a Paste or Drop command. To internalize a selection, you need to override the Internalize method of your selection’s Content class:
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173. Diagram 4
  174.  
  175.  
  176.  
  177. The above diagrams illustrate simple non-embedding parts. Things get a little more complicated with parts that support embedding, because they have to override some additional methods to deal with the single-embedded-frame case. Diagram 5 shows some (not all!) of the steps involved in internalizing a single embedded frame.
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195. Diagram 5
  196.  
  197. When internalizing a single embedded frame, ODF first clones the frame/part, and if successful calls the Content method SingleEmbeddedFrameInternalized. This method must be overridden by embedding parts to take care of integrating the new embedded part into part data.
  198.  
  199.  
  200. © 1993 - 1996 Apple Computer, Inc. All rights reserved.
  201. Apple, the Apple Logo, Macintosh, and OpenDoc are trademarks of Apple Computer, Inc., registered in the United States and other countries.